package com.hzw.saas.common.config.util;



import cn.hutool.core.exceptions.UtilException;
import com.hzw.saas.common.config.auth.Constants;
import com.hzw.saas.common.config.auth.SimpleHttpException;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;

public final class UrlUtil {
    public static String urlEncode(String value) {
        if (value == null) {
            return "";
        } else {
            try {
                String encoded = URLEncoder.encode(value, Constants.DEFAULT_ENCODING.displayName());
                return encoded.replace("+", "%20").replace("*", "%2A").replace("~", "%7E").replace("/", "%2F");
            } catch (UnsupportedEncodingException var2) {
                throw new SimpleHttpException("Failed To Encode Uri", var2);
            }
        }
    }

    public static String urlDecode(String url) throws UtilException {
        if (StringUtil.isEmpty(url)) {
            return url;
        } else {
            try {
                return URLDecoder.decode(url, Constants.DEFAULT_ENCODING.displayName());
            } catch (UnsupportedEncodingException var2) {
                throw new SimpleHttpException("Unsupported encoding", var2);
            }
        }
    }

    private UrlUtil() {
        throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
    }
}
